RPMBUILD_DIR = $(shell pwd)/rpmbuild
SUBDIRS=mod usr
define make_subdir
    @for subdir in $(SUBDIRS) ; do \
        ( cd $$subdir && make $1) \
    done;
endef

all: 3.18.25 socs

3.12.0:
	make -C mod $@
	mv mod/socs.ko mod/socs-3.12.0.ko

3.18.25:
	make -C mod $@
	mv mod/socs.ko mod/socs-3.18.25.ko

socs:
	make -C usr $@

clean:
	$(call make_subdir , clean)
	rm -f mod/socs-3.18.25.ko

rpm: all
	touch ~/.rpmmacros
	mv ~/.rpmmacros ~/.rpmmacros.bak
	echo '' > ~/.rpmmacros
	echo "%_topdir $(RPMBUILD_DIR)" >> ~/.rpmmacros
	echo "%__os_install_post %{nil}" >> ~/.rpmmacros

	cp mod/socs-3.18.25.ko $(RPMBUILD_DIR)/SOURCES/socs/bin/3.18.25/socs.ko
	cp usr/socs $(RPMBUILD_DIR)/SOURCES/socs/bin/
	tar -C $(RPMBUILD_DIR)/SOURCES/ -cvzf $(RPMBUILD_DIR)/SOURCES/socs.tar.gz socs
	rpmbuild -bb $(RPMBUILD_DIR)/SPECS/socs.spec

